var xhr;
document.getElementById("SendCode").onclick=function send(){
    var result = isPhoneNum();
    if(result){
        document.getElementById("inputCode").setAttribute("style","display:inline");
        var number = document.getElementById("Number").value;
        xhr = new XMLHttpRequest();
        xhr.open("GET","/account/send?number="+number,true);
        xhr.send(null);
        setTime();//开始倒计时
    }
    else{
        alert("请输入正确的手机号码")
    }
}

//60s倒计时实现逻辑

var number = 60;

function setTime() {
    var countdown = function(){
        if (number == 0) {
            var button=document.getElementById("SendCode");
            button.disabled=false;
            document.getElementById("SendCode").value="Resend";
            number = 60;
            return;
        } else {
            var button=document.getElementById("SendCode");
            button.disabled=true;
            document.getElementById("SendCode").value="("+number+"s)后重新发送";
            number--;
        }
        setTimeout(countdown,1000);
    }
    setTimeout(countdown,1000);


}





//校验手机号是否合法

function isPhoneNum(){

    var phonenum =document.getElementById("Number") .value;

    var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;

    if(!reg.test(phonenum)){

        alert('请输入有效的手机号码！');

        return false;

    }else{

        return true;

    }

}
